package com.xbongbong.paas.toolbox.exception;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.pro.enums.ErrorCodeEnum;
import com.xbongbong.pro.enums.errorcodes.ErrorCode;

/**
 * XBB Excption父类
 * @author kaka
 */
public class XbbException extends Exception {

    private static final long serialVersionUID = -3114017688962192849L;

    private Integer code;
    private String msg;

    public XbbException() {
        super();
    }

    public XbbException(Integer code, String msg) {
        this(code, msg, null);
    }

    public XbbException(Integer code, String msg, Object... args) {
        super(code + " " + msg);
        this.code = code;
        if (args == null) {
            this.msg = I18nMessageUtil.getMessage(msg);
        } else {
            this.msg = String.format(I18nMessageUtil.getMessage(msg), args);
        }
    }

    public XbbException(ErrorCodeEnum codeEnum) {
        this(codeEnum.getCode(), codeEnum.getMsg());
    }

    public XbbException(ErrorCodeEnum codeEnum, String msg) {
        this(codeEnum.getCode(), msg);
    }

    public XbbException(ErrorCodeEnum codeEnum, String msg, Object... args) {
        this(codeEnum.getCode(), msg, args);
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public XbbException(ErrorCode errorCode) {
        this(errorCode.getCode(), errorCode.getMsg());
    }

    public XbbException(ErrorCode errorCode, String msg) {
        this(errorCode.getCode(), msg);
    }

    public XbbException(ErrorCode errorCode, String msg, Object... args) {
        this(errorCode.getCode(), msg, args);
    }

}